package com.zzyl.nursing.controller.member;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataGraphVo;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MemberElderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@Slf4j
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 小程序绑定家人
     *
     * @param memberElderDto
     * @return
     */
    @ApiOperation("小程序绑定家人")
    @PostMapping("/add")
    public AjaxResult addFamily(@RequestBody MemberElderDto memberElderDto) {

        familyMemberElderService.addFamily(memberElderDto);
        return AjaxResult.success();
    }

    /**
     * 小程序查询家人列表
     *
     * @return
     */
    @ApiOperation("小程序查询家人列表")
    @GetMapping("/my")
    public AjaxResult queryFamily() {

        List<FamilyMemberElderVo> list = familyMemberElderService.queryFamily();

        return AjaxResult.success(list);
    }


    /**
     * 小程序分页查询家人列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("小程序分页查询家人列表")
    @GetMapping("/list-by-page")
    public R<List<MemberElderVo>> pageList(Integer pageNum, Integer pageSize) {

        List<MemberElderVo> list = familyMemberElderService.pageList(pageNum, pageSize);
        return R.ok(list);
    }

    /**
     * 查询健康数据
     *
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {

        Map<String, Map<String, Object>> map = familyMemberElderService.queryDevicePropertyStatus(deviceDto);

        return AjaxResult.success(map);
    }

    /**
     * 按天统计查询指标数据
     * @param functionId
     * @param startTime
     * @param endTime
     * @param iotId
     * @return
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(String functionId, Long startTime, Long endTime, String iotId) {

        List<DeviceDataGraphVo> deviceDataGraphVos = familyMemberElderService.queryDeviceDataListByDay(functionId, startTime, endTime, iotId);
        return AjaxResult.success(deviceDataGraphVos);
    }


    /**
     * 按周统计查询指标数据
     * @param functionId
     * @param startTime
     * @param endTime
     * @param iotId
     * @return
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(String functionId, Long startTime, Long endTime, String iotId) {


        List<DeviceDataGraphVo> deviceDataGraphVos = familyMemberElderService.queryDeviceDataListByWeek(functionId, startTime, endTime, iotId);
        return AjaxResult.success(deviceDataGraphVos);
    }

}
